package com.tacc.tyun.util;

import java.net.URLEncoder;
import java.util.Date;

/**
 * @author yu sheng qiang
 * @create 2017-03-27 16:17
 **/
public class BaseUtil {
    public static final String NUMBER_CONTENT="0123456789";
    public static final String LETTER_CONTENT="abcdefghijklmnopqrstuvwxyz";
    public static final String LETTER_NUMBER_CONTENT="0123456789abcdefghijklmnopqrstuvwxyz";
    //获取文件的后缀
    public static String acceptFileType(String fileName){
        String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
        return suffix;
    }
    //获取随机数
    public static String acceptRandom(String content,int num){
        StringBuffer sb=new StringBuffer();
        for (int i=0;i<num;i++){
            int id=(int)((Math.random())*(content.length()-1));
            sb.append(content.substring(id,id+1));
        }
        return sb.toString();
    }
    //获取id
    public static  String uId(){
        return new Date().getTime()+acceptRandom(NUMBER_CONTENT,8);
    }

    public static String urlEnodeUTF8(String str){
        String result = str;
        try {
            result = URLEncoder.encode(str,"UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
